home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / HCGS / TN.HCGS.003 < prev   
Encoding:
Text File  |  1991-06-28  |  4.1 KB  |  121 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. HyperCard IIGS
  8. #3:          Pitching Sampled Sounds 
  9.  
  10. Written by:  Mark Cecys & Matt Deatherage                          March 1991
  11.  
  12. This Technical Note describes the "relative pitch" field used in sound 
  13. resources played by HyperCard (and sound scraps that HyperCard doesn't 
  14. use)--what it does and what to put in it.
  15. _____________________________________________________________________________
  16.  
  17.  
  18. What is this relative pitch thing?
  19.  
  20. There are basically two ways to use a sound sample, in HyperCard or anywhere 
  21. else:  as a sample of a wave of definite pitch, or as a miniature "tape 
  22. recording" of some sound that is not intended to be used as a sample of 
  23. indefinite pitch.
  24.  
  25. Definite Pitch
  26.  
  27. To play a sample at the correct pitch, HyperCard assumes two things about the 
  28. sample:  it was sampled at a rate of 26.32 KHz, and the associated wave was 
  29. playing a pitch of 261.63 Hz, when it was sampled.
  30.  
  31. In the real world, where most of us live, this is not very practical.  To 
  32. help compensate for reality, the sample sound format includes a "relative 
  33. pitch" field, which can tell HyperCard (or anyone else playing the sound) how 
  34. to compensate for the difference in pitch between the sample's actual pitch 
  35. and a pitch of 261.63 Hz.
  36.  
  37. Follow these steps to calculate the relative pitch parameter for a given 
  38. sampled sound resource.  If the wave is of definite pitch, you must know the 
  39. frequency of the source wave and the sampling rate for the sample in 
  40. question.  
  41.  
  42.  
  43. 1.    Calculate the difference ratio r.  In the equation below, Fw is the
  44.       frequency of the sample (in Hz) and Fs is the sampling rate for the 
  45.       sample.  
  46.  
  47.                        261.63       Fs
  48.                 r   =  ------  X  ------
  49.                          Fw       26,320
  50.  
  51. 2.    Extract an offset to the pitch:
  52.  
  53.                 offset  =  3072  X log (r)
  54.                                       2
  55.  
  56.       (Remember that you can substitute (ln(r)/ln(2)) if your calculator
  57.       doesn't provide the log in base 2.)
  58.  
  59. 3.    If offset is negative, make it positive and set bit 15 to tell sound
  60.       players to lower the pitch instead of raise it.  If offset is
  61.       negative:
  62.  
  63.                 relative  =  |offset| +  $8000
  64.  
  65.       If offset is positive:
  66.  
  67.                 relative  =  offset
  68.  
  69. That's all.   Store the value of tuning in the sampled sound for the 
  70. "relative pitch" field and HyperCard will take care of the rest.
  71.  
  72. Indefinite pitch
  73.  
  74. Sounds which are not samples of definite pitch (for example, a thunder clap 
  75. or the sound of your mother saying "hello") should not need to be made to 
  76. match pitch.  Only sounds produced using optional parameters of HyperCard's 
  77. Play command need to go through the same process outlined for "Definite 
  78. pitch". In these cases, however, you don't need to worry about the frequency 
  79. of the sample.  Instead of using the equation provided in step 1 above, use 
  80. this instead:
  81.                          Fs
  82.                 r   =  ------
  83.                        26,320
  84.  
  85. (or just use 261.63 for Fw.)  Take the value of r and use it for steps two 
  86. and three above.
  87.  
  88.  
  89. A HyperTalk sample
  90.  
  91. The following simple button script will calculate the correct value of 
  92. relativefor you, given the other values in card fields named Fw, Fs and card 
  93. fields named offset and relativeto use as containers:
  94.  
  95. on mouseUp
  96. lock screen
  97. set numberFormat to "0"
  98. put the value of card field Fs * 261.63 into r
  99. put the value of card field Fw into denominator -- the bottom of the fraction
  100. multiply denominator by 26320
  101. divide r by denominator
  102.  
  103. put log2(r) into card field offset
  104. multiply card field offset by 3072
  105.  
  106. if card field offset <0 then
  107.     put abs(the value of card field offset) into card field tuning
  108.     add 32768 to card field relative
  109. end if
  110.  
  111. unlock screen
  112. end mouseUp
  113.  
  114.  
  115. Further Reference
  116. _____________________________________________________________________________
  117.   o   HyperCard IIgs Script Language Guide
  118.   o   Apple IIgs Technical Note #76, Miscellaneous Resource Formats
  119.   o   Apple IIgs Technical Note #99, Supplemental Scrap Types
  120.  
  121.